package core_sql.day01

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * Created by root on 2018/11/29.
  */
object WordCount {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      .setAppName("WordCount")
      .setMaster("local[*]")
    val sc = new SparkContext(conf)

    val lines: RDD[String] = sc.textFile("hdfs://bigdata01:9000/word.txt")

    val words: RDD[String] = lines.flatMap(line => line.split(" "))

    val wordAndOne: RDD[(String, Int)] = words.map(x => (x,1))

    val wordCount: RDD[(String, Int)] = wordAndOne.reduceByKey(_+_)

    val collect: Array[(String, Int)] = wordCount.sortBy(_._2).collect()

    collect.foreach(println)

  }

}
